{extend name='table'}

{block name="button"}
    {if $isMaster}
    <button class="layui-btn layui-btn-sm" data-modal='{:url("add")}'>
        <i class="layui-icon layui-icon-add-1"></i> 添加礼品
    </button>
    <button class="layui-btn layui-btn-sm layui-btn-danger" data-table-id="GiftTable" data-action='{:url("remove")}' data-rule="id#{id}">
        <i class="layui-icon layui-icon-delete"></i> 删除
    </button>
    <button class="layui-btn layui-btn-sm layui-btn-normal" data-table-id="GiftTable" data-action='{:url("state")}' data-rule="id#{id};status#1">
        <i class="layui-icon layui-icon-ok-circle"></i> 上架
    </button>
    <button class="layui-btn layui-btn-sm layui-btn-warm" data-table-id="GiftTable" data-action='{:url("state")}' data-rule="id#{id};status#0">
        <i class="layui-icon layui-icon-close-fill"></i> 下架
    </button>
    {/if}
{/block}

{block name="search"}
    <div class="layui-form layui-form-pane form-search">
        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-inline">
                <input name="keyword" value="{$get.keyword|default=''}" placeholder="礼品名称/类型" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <select name="status">
                    <option value="">- 全部 -</option>
                    <option value="1" {if input('get.status') == '1'}selected{/if}>上架</option>
                    <option value="0" {if input('get.status') == '0'}selected{/if}>下架</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-inline">
            <button class="layui-btn" data-table-search><i class="layui-icon layui-icon-search"></i> 搜 索</button>
            <button class="layui-btn layui-btn-primary" data-table-reset><i class="layui-icon layui-icon-refresh-1"></i> 重 置</button>
        </div>
    </div>
{/block}

{block name="content"}
    <table id="GiftTable" data-url="{:sysuri('index')}" data-target-search="form.form-search"></table>
{/block}

{block name="script"}
<script>
layui.use(['jquery'], function() {
    var $ = layui.$;
    let cols = [[
        {type: 'checkbox'},
        {field: 'id', title: 'ID', width: 70, sort: true},
        {field: 'image', title: '图片', width: 90, templet: function(d){ return $.layTable.showImage(d.image, true, 'ss', d.name); }},
        {field: 'name', title: '礼品名称', minWidth: 160},
        {field: 'type', title: '类型', width: 100},
        {field: 'points_required', title: '所需积分', width: 100, sort: true},
        {field: 'stock', title: '库存', width: 90, templet: function(d){ return d.stock == -1 ? '不限' : d.stock; }},
        {field: 'sort', title: '排序', width: 80, sort: true},
        {field: 'status', title: '状态', width: 90, templet: function(d){ return d.status==1?'<span class="color-green">上架</span>':'<span class="color-red">下架</span>'; }},
        {field: 'create_time', title: '创建时间', width: 170, sort: true},
        {toolbar: '#ToolbarTpl', title: '操作', fixed: 'right', minWidth: 140}
    ]];
    $('#GiftTable').layTable({ even: true, height: 'full-200', cols: cols });
});
</script>

<script type="text/html" id="ToolbarTpl">
    {if $isMaster}
    <a class="layui-btn layui-btn-xs" data-title="编辑礼品" data-modal='{:url("edit")}?id={{d.id}}'>编 辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" data-confirm="确定要删除该礼品吗？" data-action='{:url("remove")}' data-value="id={{d.id}}">删 除</a>
    {/if}
</script>
{/block}
